package cn.dakaqi.qnzyz;

import cn.dakaqi.entities.Activity;
import cn.dakaqi.util.ConfigUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ResourceBundle;

/**
 * Authoer:chunyang
 * ProjectName:Volunteer
 * Date: 2015/7/6.
 * Description:
 */
public class BHActivity implements Serializable
{

    private static final long serialVersionUID = 6698026513071310009L;
    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd HHmmss");

    private String activityCode;//活动一号通编号,全网唯一
    private String activityName;//活动名称
    private String activitySummary;//活动简介
    private String activityPostImgSmall;//活动介绍小图片，用于列表显示
    private String activityLocation;//活动地点
    private String activityStartPeriod;//活动开始时间 yyyyMMdd HHmmss
    private String activityEndPeriod;//活动结束时间 yyyyMMdd HHmmss
    private String activityDetailUrl;//活动介绍详细页面链接
    private String activityRegStartPeriod;//活动开始注册时间 yyyyMMdd HHmmss
    private String activityRegEndPeriod;//活动结束注册时间 yyyyMMdd HHmmss
    private String activityCatalog;//活动分类
    private String groupCode;//志愿者团体一号通编号,全网唯一
    private String groupName;//志愿者团体名称
    private String activityScore;//活动积分

    public static BHActivity nativeact2bhact(Activity activity)
    {
        String activityStartPeriod = "", activityEndPeriod = "", activityLocation = "", activityRegEndPeriod = "", activityRegStartPeriod = "", activityPostImgSmall = "";
        try
        {
            if (StringUtils.isNotEmpty(activity.getImgs()))
            {
                String imgs[] = activity.getImgs().split(";");
                activityPostImgSmall = imgs[0];
            }


            activityLocation = activity.getAddress().replace(activity.getProvince(), "");
            if (StringUtils.isNotEmpty(activityLocation))
            {
                activityLocation = activityLocation.replace(activity.getDistrict() == null ? "" : activity.getDistrict(), "");
                activityLocation = activityLocation.replace(activity.getCity() == null ? "" : activity.getCity(), "");
                activityLocation = activity.getProvince() == null ? "" : activity.getProvince() + "" + activity.getCity() == null ? "" : activity.getCity() + "" + activity.getDistrict() == null ? "" : activity.getDistrict() + "" + activityLocation;
            }
            activityStartPeriod = sdf2.format(sdf.parse(activity.getStartTime() + ":00"));
            activityEndPeriod = sdf2.format(sdf.parse(activity.getEndTime() + ":00"));
            activityRegEndPeriod = activityEndPeriod;
            activityRegStartPeriod = sdf2.format(activity.getCreateTime());

        } catch (ParseException e)
        {
            e.printStackTrace();
        }

//        ResourceBundle bundle = ResourceBundle.getBundle("parameter");
//        String webRootPath = bundle.getString("app.root.path");
        String webRootPath = ConfigUtil.getAppRoot();
        if (webRootPath.endsWith("/") == false)
            webRootPath = webRootPath + "/";
        String detailUrl = webRootPath + "api/v1/activity/id/" + activity.getId();
        BHActivity bhActivity = new BHActivity(activity.getActivityCode(), activity.getTags(), detailUrl, activityEndPeriod, activityLocation,
                activity.getName(), activityPostImgSmall, activityRegEndPeriod, activityRegStartPeriod,
                activityStartPeriod, activity.getDemo(), activity.getGroup().getGroupCode(), activity.getGroup().getName(), "0");
        return bhActivity;

    }

    public static Activity bhact2nativeact(BHActivity bhActivity)
    {
//        Activity activity = new Activity();
//        activity.setId(-100);
//        activity.setName(bhActivity.getActivityName());
//        activity.setDemo(bhActivity.getActivitySummary());
//        activity.setImg(bhActivity.getActivityPostImgSmall());
//
//        String startDay = "",startHour = "",startMinute = "",endDay = "",endHour = "",endMinute = "";
//        try
//        {
//            if(StringUtils.isNotEmpty(bhActivity.getActivityStartPeriod()) && !"null".equals(bhActivity.getActivityStartPeriod()))
//            {
//                String startTemp = sdf.format(sdf.parse(bhActivity.getActivityStartPeriod()));
//                startDay =  startTemp.substring(0,10);
//                startHour =  startTemp.substring(11,13);
//                startMinute =  startTemp.substring(14,16);
//
//                startTemp = sdf.format(sdf.parse(bhActivity.getActivityEndPeriod()));
//                endDay =  startTemp.substring(0,10);
//                endHour =  startTemp.substring(11,13);
//                endMinute =  startTemp.substring(14,16);
//
//                Date startDate = sdf.parse(bhActivity.getActivityStartPeriod().replace(".0", ""));
//                Date curDate = Calendar.getInstance().getTime();
//                Date endDate = sdf.parse(bhActivity.getActivityEndPeriod().replace(".0",""));
//                if(curDate.before(startDate) && curDate.before(endDate))
//                    activity.setStatus(Activity.STATUS_NOT_START);
//                else if(curDate.after(startDate) && curDate.before(endDate))
//                    activity.setStatus(Activity.STATUS_HAS_START);
//                else if(curDate.after(endDate))
//                    activity.setStatus(Activity.STATUS_END);
//            }
//
//        } catch (ParseException e)
//        {
//            e.printStackTrace();
//        }
//
//        activity.setDetailUrl(bhActivity.getActivityDetailUrl());
//        activity.setStartDay(startDay);
//        activity.setStartHour(startHour);
//        activity.setStartMinute(startMinute);
//        activity.setEndDay(endDay);
//        activity.setEndHour(endHour);
//        activity.setEndMinute(endMinute);
//        activity.setActivityCode(bhActivity.getActivityCode());
//        activity.setServicetype(bhActivity.getActivityCatalog());
//        activity.setActStartApplyTime(bhActivity.getActivityRegStartPeriod());
//        activity.setActEndApplyTime(bhActivity.getActivityEndPeriod());
//        Map<String,String> latLngMap = LatitudeUtils.getGeocoderLatitude(bhActivity.getActivityLocation());
//        if(null != latLngMap)
//        {
//            String lng  = latLngMap.get("lng");
//            String lat  = latLngMap.get("lat");
//            activity.setLng(Double.valueOf(lng));
//            activity.setLat(Double.valueOf(lat));
//            Map<String,String> map = LatitudeUtils.getGeocoderAddress(Double.parseDouble(lat), Double.parseDouble(lng));
//            if(null != map)
//            {
//                activity.setProvince(map.get("province"));
//                activity.setCity(map.get("city"));
//                activity.setDistrict(map.get("district"));
//                String temp = bhActivity.getActivityLocation().replace(activity.getProvince(),"");
//                temp = temp.replace(activity.getCity(), "");
//                temp = temp.replace(activity.getDistrict(), "");
//                activity.setAddress(activity.getProvince()+activity.getCity()+activity.getDistrict()+temp);
//            }
//        }
//        //设置活动进行状态
//
////        groupCode	M	C	12	志愿者团体一号通编号,全网唯一

        return null;
    }

    public BHActivity()
    {
    }

    public BHActivity(String activityCode, String activityCatalog, String activityDetailUrl, String activityEndPeriod, String
            activityLocation, String activityName, String activityPostImgSmall, String activityRegEndPeriod, String
                              activityRegStartPeriod, String activityStartPeriod, String activitySummary, String groupCode, String groupName, String activityScore)
    {
        this.activityCode = activityCode;
        this.activityCatalog = activityCatalog;
        this.activityDetailUrl = activityDetailUrl;
        this.activityEndPeriod = activityEndPeriod;
        this.activityLocation = activityLocation;
        this.activityName = activityName;
        this.activityPostImgSmall = activityPostImgSmall;
        this.activityRegEndPeriod = activityRegEndPeriod;
        this.activityRegStartPeriod = activityRegStartPeriod;
        this.activityStartPeriod = activityStartPeriod;
        this.activitySummary = activitySummary;
        this.groupCode = groupCode;
        this.groupName = groupName;
        this.activityScore = activityScore;
    }

    public String getActivityScore()
    {
        return activityScore;
    }

    public void setActivityScore(String activityScore)
    {
        this.activityScore = activityScore;
    }

    public String getActivityCatalog()
    {
        return activityCatalog;
    }

    public void setActivityCatalog(String activityCatalog)
    {
        this.activityCatalog = activityCatalog;
    }

    public String getActivityDetailUrl()
    {
        return activityDetailUrl;
    }

    public void setActivityDetailUrl(String activityDetailUrl)
    {
        this.activityDetailUrl = activityDetailUrl;
    }

    public String getActivityEndPeriod()
    {
        return activityEndPeriod;
    }

    public void setActivityEndPeriod(String activityEndPeriod)
    {
        this.activityEndPeriod = activityEndPeriod;
    }

    public String getActivityLocation()
    {
        return activityLocation;
    }

    public void setActivityLocation(String activityLocation)
    {
        this.activityLocation = activityLocation;
    }

    public String getActivityName()
    {
        return activityName;
    }

    public void setActivityName(String activityName)
    {
        this.activityName = activityName;
    }

    public String getActivityPostImgSmall()
    {
        return activityPostImgSmall;
    }

    public void setActivityPostImgSmall(String activityPostImgSmall)
    {
        this.activityPostImgSmall = activityPostImgSmall;
    }

    public String getActivityRegEndPeriod()
    {
        return activityRegEndPeriod;
    }

    public void setActivityRegEndPeriod(String activityRegEndPeriod)
    {
        this.activityRegEndPeriod = activityRegEndPeriod;
    }

    public String getActivityRegStartPeriod()
    {
        return activityRegStartPeriod;
    }

    public void setActivityRegStartPeriod(String activityRegStartPeriod)
    {
        this.activityRegStartPeriod = activityRegStartPeriod;
    }

    public String getActivityStartPeriod()
    {
        return activityStartPeriod;
    }

    public void setActivityStartPeriod(String activityStartPeriod)
    {
        this.activityStartPeriod = activityStartPeriod;
    }

    public String getActivitySummary()
    {
        return activitySummary;
    }

    public void setActivitySummary(String activitySummary)
    {
        this.activitySummary = activitySummary;
    }

    public String getGroupCode()
    {
        return groupCode;
    }

    public void setGroupCode(String groupCode)
    {
        this.groupCode = groupCode;
    }

    public String getGroupName()
    {
        return groupName;
    }

    public void setGroupName(String groupName)
    {
        this.groupName = groupName;
    }

    public String getActivityCode()
    {
        return activityCode;
    }

    public void setActivityCode(String activityCode)
    {
        this.activityCode = activityCode;
    }
}
